import {getActionSimple} from "@/utils/axiosUtils";
import {DictUtils} from "@/utils/dictUtils";

const personTypeMapping = {
  "00":""
}

const indexChart = {
  state:{
    //可查询年份列表
    yearList:[],
    //乡镇街道列表
    unitList:[],
    //默认选中的街道
    selectUnitId:null,
  },
  actions:{
    //获取默认选中的街道
    async getSelectUnitId(context){
      let {commit} = context
      //TODO
      const { userType } = context.getters
      const { unitId } = context.getters
      //获取单位id
      let searchUnitId = null
      //监管者-01 管理员-00  普通用户-02
      if (unitId && userType === '01') {
        searchUnitId = unitId
      } else if (userType === '00') {
        //如果是管理员
        searchUnitId =await DictUtils.getDicValue("sys_config","default_statistics_area")
      }else{
        //普通用户 查询的就是自己所在单位的地区数据.
        searchUnitId = +unitId
      }
      commit('SET_SELECT_UNIT_ID',+searchUnitId)
    },
    //获取所有年份
    async getYearList(context) {
      let {commit} = context
      try {
        let result = await getActionSimple('/nongjt/certificate_count/yearList')
        commit('SET_YEAR_LIST',result)
      } catch (e) {
        console.log("获取所有年份列表异常",e)
      }
    },
    //获取所有单位列表
    async getUnitConfigList(context) {
      let {commit} = context
      try {
        let result = await getActionSimple('/nongjt/unit/listAll')
        commit('SET_UNIT_LIST',result)
      } catch (e) {
        console.log("获取所有单位列表异常",e)
      }

    },
  },
  mutations:{
    SET_YEAR_LIST(state,value){
      state.yearList = value
    },
    SET_UNIT_LIST(state,value){
      state.unitList = value
    },
    SET_SELECT_UNIT_ID(state,value){
      state.selectUnitId = value
    },
  }
}
export default indexChart
